package com.filebackup.cloudapi;

import java.util.HashMap;
import java.util.Map;

public class CloudApiFactory {

	private static CloudApiFactory instance = new CloudApiFactory();

	private static Map<String, Class> apiMap;

	private CloudApiFactory() {
		init();
	}

	private void init() {
		apiMap = new HashMap<String, Class>();
		apiMap.put("ali", AliApi.class);
		apiMap.put("dropbox", DropboxApi.class);
	}

	public static CloudApiFactory getInstance() {
		return instance;
	}

	public static String[] getApiNames() {

		return apiMap.keySet().toArray(new String[0]);
	}

	public static ICloudApi getApi(String name) {
		Class apiClass = apiMap.get(name);
		try {
			return (ICloudApi) apiClass.newInstance();
		} catch (InstantiationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return null;
	}
}
